package com.snopy.tree;

import com.snopy.utils.ArrayUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author snopy
 * @version 1.0.0
 * @classname HuffmanTree
 * @description graph
 * @email 77912204@qq.com
 * @date 2022/10/27 16:46
 */
public class HuffmanTree {
    private Node[] huffmanTree;
    private int pos;
    public HuffmanTree(int[] weigths) {
        this.pos = 0;
        this.huffmanTree = new Node[2 * weigths.length - 1];
    }
    private Node[] buildHuffManTree(int[] weights,Node[] huffmanTree){
        //1.构造森林全是根
        for (int i=0;i<huffmanTree.length;i++){
            if (i<weights.length){
                huffmanTree[i] = new Node(weights[i],0,0,0);
            }else {
                huffmanTree[i] = new Node(-1,0,0,0);
            }
        }
        //4.重复2、3剩单根
        Arrays.sort(weights);
        int last = weights.length-1;
        do{
         //2.选择两小造新树
            last++;
            last++;
         //3.删除两小添新树
        }while (last < 2*huffmanTree.length-1);
        return null;
    }
    public void put(int weight,int parent,int lch,int rch){

    }
    static class Node{
        int weight;
        int parent,lch,rch;

        public Node(int weight, int parent, int lch, int rch) {
            this.weight = weight;
            this.parent = parent;
            this.lch = lch;
            this.rch = rch;
        }

        public Node(int weight, int lch, int rch) {
            this.weight = weight;
            this.lch = lch;
            this.rch = rch;
        }
    }


}
